<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>耗材出库</title>
</head>
<body>
	<script src="<c:url value="/js/jquery-migrate-1.1.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery.jqprint-0.3.js"/>"></script>
	<script type="text/javascript">
	$(function(){
		$("#lmb—hcck-add").linkbutton({onClick:function(){						
			$("#lmb_win-hc-ck-add").window("open");
			$("#lmb_outstock_form").form("clear");
			$('#lmb-outstock-draw-dg').datagrid('loadData', { total: 0, rows: [] }); 
		}});
		
		//lmb-outstock-lydh,lmb-outstock-jbr, lmb-outstock-ckrq ,lmb-outstock-tlr
		var lmb_ly_objectId =  undefined;//领用对象编号
		var lmb_ly_objectName = undefined;//领用对象名称
		var lmb_ly_ckId =  undefined;//领用对象编号
		var lmb_ly_ckName = undefined;//领用对象名称
		//选择提领单
		$("#lmb-outstock-lydh").combogrid({onChange: function(newValue, oldValue){			
			//根据id查找出仓库
			var collarId = $("#lmb-outstock-lydh").combogrid("getValue");
			$.getJSON("to_findLyBylydh", {"collarId": collarId}, function(data){
				$("#lmb-outstock-blyckId").textbox("setValue",data.collarStorehouse);
				$("#lmb-outstock-blyck").textbox("setValue",data.collarStorehouseName);		
				$("#lmb-outstock-ckdxId").textbox("setValue",data.collarObject);
				$("#lmb-outstock-ckdx").textbox("setValue",data.collarObjectName);		
			});	
			
			//根据id查找提领单详情
			$("#lmb-outstock-draw-dg").datagrid({
				url:'to_findLyxqByLyId',
				queryParams:{
	    			collarId: collarId
				}
			});
		}});
		
		//提交数据
		$("#lmb-outstock-submit").linkbutton({onClick: function(){	
			var rows = $('#lmb-outstock-draw-dg').datagrid('getRows');
			
			//药品编号，药品名称，批号，单位，库存数量，结存数量，盈亏数量
			for(var i = 0; i < rows.length; i ++){
				generateHiddenLmb_chuku(rows[i], "CId", i);
				generateHiddenLmb_chuku(rows[i], "CName", i);
				generateHiddenLmb_chuku(rows[i], "BatchNum", i);
				generateHiddenLmb_chuku(rows[i], "Norms", i);
				generateHiddenLmb_chuku(rows[i], "Num", i);
			} 
			
			$("#lmb_outstock_form").form('submit',{
				url: 'to_hcck',
			    onSubmit: function(){	
					var jg= $(lmb_outstock_form).form("validate");
					if(jg==true){
						for(var i=0;i<rows.length;i++){
							var jg1=rows[i].cdNum < rows[i].cdKcnum;
							if(jg1==false){					
								$.messager.alert('提示', "领用数量大于库存数量，不能出库！ ");
								return false;
							}							
						}
					}else{
						$.messager.alert('提示', "数据不完善，请完善数据！ ");
						return jg;
					}				
			    },
			    success:function(data){			    	
					$.messager.alert('提示', "出库成功！");
					$(this).form("clear");
					$("#lmb_win-hc-ck-add").window("close");
					$("#lmb-hcck_dg").datagrid("reload");
					//重新加载提领单
					$("#lmb-outstock-lydh").combogrid({
						 url:'to_findAllYspwly',
					});
					$('#lmb-outstock-draw-dg').datagrid('loadData', { total: 0, rows: [] }); 
			    }
			});	
				
		}});
		
		//创建隐式表单域来保存明细
		function generateHiddenLmb_chuku(row, name, i){
			var lmb_outstock_form = $('#lmb_outstock_form');
			$("<input type='hidden' x='y'>")
				.attr("name", "conOutDet[" + i + ']' + '.cod' + name)
				.val(row['cd' + name])
				.appendTo(lmb_outstock_form);
		}	
		
		// 刷新
		$("#lmb—hcck-sx").linkbutton({onClick:function(){
			$("#lmb-hcck_dg").datagrid({
	    		url: 'toLmbfindAllck', 
	    		method: 'get',
	    		queryParams: {
	    			page:1, 
			    	rows:5    	
	    		}});
		}});
		
		//根据条件搜索
		$('#lmb—hcck-sousuo').searchbox({
		    searcher:function(value,name){
		    	alert(1);
		    	$("#lmb-hcckDet-dg").datagrid({	    		
		    		url:'toLmbfindCkjlByID',
		    		method: 'post', 
		    		queryParams: {
		    			page:1, 
				    	rows:5,  
		    			coId: value
		    	}});
		    }		
		}); 
		
		//日期转换
		function lmb_todate_ck(value){
            if(value){
				var date = new Date(value);  
                return date.toLocaleDateString();
			}
        }
		
		//查看计划明细-打印
		$("#lmb—hcck-ckxq").linkbutton({onClick: function(){
			
			var rows = $("#lmb-hcck_dg").datagrid("getSelections");
			if(rows.length == 1){	
				$('#lmb-hcckDet-window').window("open");
				var coId = rows[0].coId;
				$.getJSON("toLmbfindCkByckId", {"coId": coId}, function(data){
					$("#lmb-hcckDet-ckdh").linkbutton({text: data.coId});
					$("#lmb-hcckDet-lydh").linkbutton({text: data.coVoucherId});
					$("#lmb-hcckDet-lyck").linkbutton({text: data.cockName});
					$("#lmb-hcckDet-cksj").linkbutton({text: lmb_todate_ck(data.coDate)});
					$("#lmb-hcckDet-ckdx").linkbutton({text: data.coObjectName});
					$("#lmb-hcckDet-jbr").linkbutton({text: data.coOperatorName});
					$("#lmb-hcckDet-tlr").linkbutton({text: data.coTlrName});
				});	
				
				 //根据id查看详情	
				 $("#lmb-hcckDet-dg").datagrid({
					url:'toLmbfindckxq',
					width: '100%',
					queryParams:{					
						coId: coId,
		    			page:1, 
		    			rows:10
					}
				});
			}else{
				$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
			}
		}});

		//点击按钮打印
		$("#lmb-hcckDet-print").linkbutton({
			onClick: function(){
				$("#lmb-hcckDet-printArea").jqprint();
			}
		});
	});
</script>
	 <table id="lmb-hcck_dg" class="easyui-datagrid" data-options="
			url:'toLmbfindAllck',
			fitColumns:true,fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#lmb—hcck',
			border:false
			">
		<thead>
			<tr>
				<th data-options="field:'',checkbox:true"></th>
				<th data-options="field:'coId',width:'20%'">出库单号</th>
				<th data-options="field:'coVoucherId',width:'19%'">领用单号</th>
				<th data-options="field:'cockName',width:'16%'">领用仓库</th>
				<th data-options="field:'coDate', width:'11%',
						formatter:function(value){
                          if(value){
							var date = new Date(value);  
                            return date.toLocaleDateString();
						  }
                 }">出库时间</th>
                 <th data-options="field:'coObjectName',width:'11%'">出库对象</th>
				<th data-options="field:'coOperatorName',width:'10%'">经办人</th>						
				<th data-options="field:'coTlrName',width:'10%'">提领人</th>	
			</tr>
		</thead>
	</table>
	
	<div id="lmb—hcck">
		<a id="lmb—hcck-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加出库记录</a>
		<a id="lmb—hcck-ckxq" class="easyui-linkbutton" data-options="iconCls:'icon-xiangqing',plain:true">出库详情</a>
		<a id="lmb—hcck-sx" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input id="lmb—hcck-sousuo" class="easyui-searchbox" data-options="menu: '#lmb—hcck-mm', width: 250, prompt: '请输入要查询的内容'"/>
	</div> 
	
	<!-- 搜索栏 -->
	<div id="lmb—hcck-mm" style="width:120px">
	    <div data-options="name:'ckd'">出库单</div>
	</div>
	
	<!--1、查询所有已审批未出库的领用单 2、根据领用单号查找详情  -->
	<!-- 领用单号、经办人、出库日期、提领人、被领用仓库、出库对象 -->
	<!-- 出库数据 -->
	<div id="lmb_win-hc-ck-add" class="easyui-window" title="录入出库信息" data-options="collapsible:true,minimizable:false,maximizable:true,modal:true,iconCls:'icon-save',closed: true" style="width:800px;height:320px;padding:5px;">
		<form id="lmb_outstock_form" method="post" style="padding:0px;">
		<table width="100%" style="background: rgb(236,243,255); padding: 10px; border-radius: 5px;">
			<tr>
				<td style="width:35%;">
					<select id="lmb-outstock-lydh" class="easyui-combogrid" name="conOutbound.coVoucherId"				
						data-options="
							label: '领用单号',
							labelAlign:'right',
							required:true,
							width: '85%',
							panelWidth: '305',
							panelHeight: 'auto',
							url: 'to_findAllYspwly',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'collarId',
							textField: 'collarId',
							columns: [[				
								{field:'collarId',title:'领用单号',width:120},
								{field:'collarApprovepeopleName',title:'审批人',width:60},
								{field:'collarState',title:'审批状态',width:60},
								{field:'collarCkstatus',title:'提领状态',width:60}
							]]
					"></select>
				</td>
				<td style="width:33%;">
					<select class="easyui-combogrid" id="lmb-outstock-jbr" name="conOutbound.coOperator"
						data-options="
							label: '经办人',
							width: '85%',
							labelAlign:'right',
							panelWidth: '290',
							panelHeight: 'auto',
							required:true,
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>	
				<td style="width:33%;">
					<input id="lmb-outstock-ckrq"class="easyui-datebox" name="conOutbound.coDate"
						data-options="label:'出库日期',labelAlign:'right',width:'70%',required:true">
				</td>			
			</tr>
			<tr>				
				<td>
					<select class="easyui-combogrid" id="lmb-outstock-tlr" name="conOutbound.coTlr"
						data-options="
							label: '提领人',
							width: '85%',
							labelAlign:'right',
							panelWidth: '290',
							panelHeight: 'auto',
							required:true,
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>
				<td>
					<input id="lmb-outstock-blyck"  class="easyui-textbox"
						data-options="label:'被领用仓库',labelAlign:'right',width:'85%',required:true">
				</td>
				<td>
					<input id="lmb-outstock-ckdx"  class="easyui-textbox"
						data-options="label:'出库对象',width:'70%',labelAlign:'right',required:true">
				</td>					
			</tr>
			<tr style="display:none;">
				<td>
					<input id="lmb-outstock-blyckId"  class="easyui-textbox" name="conOutbound.coBlyck"
						data-options="label:'被领用仓库Id',width:'60%'">
				</td>
				<td>
					<input id="lmb-outstock-ckdxId"  class="easyui-textbox" name="conOutbound.coObject"
						data-options="label:'出库对象Id',width:'60%'">
				</td>	
			</tr>
		</table>
		
		<!-- 订单明细 -->
		<div style="margin: 5px; margin-top:35px;">
			<div id="lmb-outstock-tabs" class="easyui-tabs" style="width:100%; margin-top:10px;" 
				data-options="plain:true,narrow:true">
				
				<div title="提领明细" style="padding:10px;">
					<table id="lmb-outstock-draw-dg" class="easyui-datagrid" 
								data-options="
								iconCls: 'icon-edit',
								singleSelect:true,						
								width: '100%'
								">
							<thead>
								<tr><!-- 耗材编号，耗材名称，批号，单位，数量
								cdCId,cdCName,cdBatchNum,cdNorms,cdNum-->
								
									<th data-options="field:'cdCId',width:'24%',align:'center'">药品编号</th>			
									<th data-options="field:'cdCName',width:'24%',align:'center'">药品名称</th>
									<th data-options="field:'cdBatchNum',width:'15%',align:'center'">批号</th>
									<th data-options="field:'cdNorms',width:'12%',align:'center'">单位</th>
									<th data-options="field:'cdNum',width:'12%',align:'center'">提领数量</th>
									<th data-options="field:'cdKcnum',width:'12%',align:'center'">库存数量</th>
								</tr>
							</thead>
					</table>
				</div>							
			</div>						
		</div>
	
		<!-- 确认按钮 -->
		<a id="lmb-outstock-submit" class="easyui-linkbutton" style="margin-top:15px;" data-options="iconCls:'icon-ok'">出库</a>
	</form>
	</div>	
	
	<!--查看详情窗口-打印 -->
	<div id="lmb-hcckDet-window" class="easyui-window" title="采购计划详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div id="lmb-hcckDet-printArea" data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">			
				<form id="lmb_hcckDet_form" method="post">
					<h1 style="text-align: center">耗材采购计划</h1>
					<table width="100%">		
						<tr>	
							<td>出库单号: <a id="lmb-hcckDet-ckdh"  name="coId"     class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>领用单号: <a id="lmb-hcckDet-lydh"  name="coVoucherId"  class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>领用仓库: <a id="lmb-hcckDet-lyck"  name="cockName"   class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>出库时间:  <a id="lmb-hcckDet-cksj" name="coDate"        class="easyui-linkbutton" data-options="plain:true"></a></td>			
						</tr>
						<tr>
							<td>出库对象:<a id="lmb-hcckDet-ckdx" name="coObjectName" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>经办人:<a id="lmb-hcckDet-jbr"   name="coOperatorName" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>提领人:<a id="lmb-hcckDet-tlr"   name="coTlrName" class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
					</table>
						
					<div style="margin: 5px;">
						<table id="lmb-hcckDet-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',
								singleSelect: true,										
								width: '100%'						
						">			
							<thead>
								<tr>	
									<th data-options="field:'codId',width:'23%',align:'center'">出库详情编号</th>	
									<th data-options="field:'codCId',width:'20%',align:'center'">耗材编号</th>					
									<th data-options="field:'codCName',width:'17%',align:'center'">耗材名称</th>
									<th data-options="field:'codBatchNum',width:'13%',align:'center'">批号</th>
									<th data-options="field:'codNorms',width:'13%',align:'center'">单位</th>
									<th data-options="field:'codNum',width:'13%',align:'center'">数量</th>
								</tr>
							</thead>
						</table>									
					</div>
				</form>				
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="lmb-hcckDet-print"  class="easyui-linkbutton" data-options="iconCls:'icon-print', plain:true">打印</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#lmb-hcckDet-window').window('close');">取消</a>
			</div>			
		</div>
	</div>
	
	
</body>
</html>